class WebSocketManager {
  private static instance: WebSocket | null = null;

  static getInstance(url: string, protocols?: string | string[]): WebSocket {
    if (!WebSocketManager.instance || WebSocketManager.instance.readyState !== WebSocket.OPEN) {
      WebSocketManager.instance = new WebSocket(url, protocols);
    }
    return WebSocketManager.instance;
  }

  static closeInstance() {
    if (WebSocketManager.instance) {
      WebSocketManager.instance.close();
      WebSocketManager.instance = null;
    }
  }
}

export default WebSocketManager;
